<?php
class setting_data extends MX_Controller{

	public function data($data){
		$this->load->library('session');
		/*
		$search=$this->input->post('search');
		$departement=$this->input->post('search_region');
		$category_id=$this->input->post('search_category');
		$code_postal=$this->input->post('search_cp');
		*/
		$category_id=$this->session->userdata('category_id');
		
		$code_postal=$this->session->userdata('search_cp');
		$search=$this->session->userdata('search');
		$departement=$this->session->userdata('search_region');
		$option=$this->session->userdata('option');
		
		
		$setting =$this->load->Module('setting/admin');
		$this->template=$this->config->config['front_template'];
	
	
		$localisation= $this->load->module('localisation/index');
		$location=$localisation->getlocation();
		//chercher location par code postal ou region (priorite Region)
		$location->getlocationCodePostal($code_postal);
		$location->Region=$this->session->userdata('search_region');
		if($location->Region=='')$location->departement='';
	
		$location->set_location_by_region();
	
		$name_region=$location->Nom_Region;
		$region=$location->region();
		$list_departement=$location->OptionDepartement();
		$villeList='';//$location->OptionVille($code_postal);
	
		$category= $this->load->module('category/index');

		$this->load->driver('cache');
		
		// Save into the cache for 5 minutes
		if ( ! $menu_category = $this->cache->file->get('menu_category'))
		{
			$menu_category=$category->check_list_cats(0, 0,  0, null,$this->config->config['base_url']);
	
			$this->cache->file->save('menu_category', $menu_category, 300);
		}
		$search_category ='search_category_'.$category_id;
		if ( ! $$search_category = $this->cache->file->get('search_category'))
		{
			$$search_category=$category->dropdown_option_cats($category_id);
			$this->cache->file->save($search_category, $$search_category, 300);
		}		
		$search_category =$$search_category;
		//terminer cache categorie deroulant
		
		//on ne cache pas la liste de region il y un cache dans bd 
		$regionList=$location->OptionRegion();
		
		$this->load->helper('url'); 
		$current_url=current_url();
		$filtre_type=$this->session->userdata('filtre_type');
		if($filtre_type=='')$filtre_type='toutes';
		$filtre_class=array(
				'toutes'=>'',
				'Particuliers'=>'',
				'Professionnels'=>''
				);
		$filtre_class[$filtre_type]='class="active"';
		
		$nav_class=array(
				'demande'=>'',
				'offre'=>'',
				'deposer'=>'',
				'boutique'=>'',
				'mes_annonces'=>'',
				'aides'=>'',
				);

		$getFilter= $this->load->module('setting/option');
		$filter=$getFilter->getFilters($category_id,$option,true);
		
		$dataGeneral=array(
				'departement'=>$departement,
				'menu_category'=>$menu_category,
				'current_url'=>$current_url,
				'nav_class'=>$nav_class,
				'paging'=>'',
				'nb'=>0,
				'nb_particulier'=>0,
				'nb_professionnells'=>0,
				'filtre_class'=>$filtre_class,				
				'search'=>$search,
				'search_category'=>$search_category,
				'departementList'=>$list_departement,
				'region'=>$region,
				'name_region'=>$name_region,
				'code_postal'=>$code_postal,
				'regionList'=>$regionList,
				'villeList'=>$villeList,
				'filter'=>$filter
		);
		if(!empty($data)) return array_merge($dataGeneral, $data);
	
		return $dataGeneral;
	}
}